CXX := g++
CXXFLAGS := -std=c++20
THIRD_PARTY_INCLUDE := -I./ThirdParty/include
THIRD_PARTY_LIB_DIR := -L./ThirdParty/lib -L./ThirdParty/bin
THIRD_PARTY_LIBS := -lavcodec -lavdevice -lavformat -lavutil -lswresample -lswscale -lavfilter -lglfw -lglm -lfreetype -lbrotlidec -lopencv_imgcodecs -lopencv_imgproc -lmidifile -lopencv_core -lpng -lz -lpostproc -lpthread

# CORE_TARGET := MusicLightCore
# PREVIEWER_TARGET := MusicLightPreviewer
CORE_TARGET := Core
PREVIEWER_TARGET := Previewer

all: $(CORE_TARGET) $(PREVIEWER_TARGET)

core: $(CORE_TARGET)

previewer: $(PREVIEWER_TARGET)

obj/glad.o: ThirdParty/glad/glad.c
	$(CXX) $(CXXFLAGS) $(THIRD_PARTY_INCLUDE) -g -c $< -o $@

obj/%.o: src/%.cpp
	$(CXX) $(CXXFLAGS) $(THIRD_PARTY_INCLUDE) -g -c $< -o $@

CORE_OBJS =  \
	obj/AudioProcessor.o \
	obj/BackgroundPicture.o \
	obj/BaseTypes.o \
	obj/Caption.o \
	obj/CommandProcessor.o \
	obj/Core.o \
	obj/DoubleSectorDrawer.o \
	obj/GaussianBlur.o \
	obj/GetFrame.o \
	obj/glad.o \
	obj/GLConfig.o \
	obj/GLSLActivator.o \
	obj/InstrumentBackground.o \
	obj/InstrumentLabels.o \
	obj/MIDIReader.o \
	obj/MLFrame.o \
	obj/MLObj.o \
	obj/MLProgressbar.o \
	obj/MLRender.o \
	obj/Note.o \
	obj/NotesManager.o \
	obj/NotesTrack.o \
	obj/OptionsGetter.o \
	obj/ParticleDrawer.o \
	obj/ParticleManager.o \
	obj/ParticleObj.o \
	obj/ParticleTrack.o \
	obj/RecordDrawer.o \
	obj/RecordPicture.o \
	obj/Renderer.o \
	obj/SectorDrawer.o \
	obj/Stream.o \
	obj/TextDrawer.o \

PREVIEWER_OBJS = \
	obj/AudioProcessor.o \
	obj/BackgroundPicture.o \
	obj/BaseTypes.o \
	obj/Caption.o \
	obj/DoubleSectorDrawer.o \
	obj/GaussianBlur.o \
	obj/GetFrame.o \
	obj/glad.o \
	obj/GLConfig.o \
	obj/GLSLActivator.o \
	obj/InstrumentBackground.o \
	obj/InstrumentLabels.o \
	obj/MIDIReader.o \
	obj/MLFrame.o \
	obj/MLObj.o \
	obj/MLPreviewRender.o \
	obj/MLProgressbar.o \
	obj/Note.o \
	obj/NotesManager.o \
	obj/NotesTrack.o \
	obj/OptionsGetter.o \
	obj/ParticleDrawer.o \
	obj/ParticleManager.o \
	obj/ParticleObj.o \
	obj/ParticleTrack.o \
	obj/PreviewerCommandProcessor.o \
	obj/Previewer.o \
	obj/PreviewRenderer.o \
	obj/RecordDrawer.o \
	obj/RecordPicture.o \
	obj/SectorDrawer.o \
	obj/Stream.o \
	obj/TextDrawer.o \

$(CORE_TARGET): $(CORE_OBJS)
	$(CXX) $(CXXFLAGS) $(THIRD_PARTY_LIB_DIR) $^ -g -o $@ $(THIRD_PARTY_LIBS) -Wl,-rpath=./ThirdParty/bin

$(PREVIEWER_TARGET): $(PREVIEWER_OBJS)
	$(CXX) $(CXXFLAGS) $(THIRD_PARTY_LIB_DIR) $^ -g -o $@ $(THIRD_PARTY_LIBS) -Wl,-rpath=./ThirdParty/bin

clean:
	rm -f $(CORE_OBJS) $(PREVIEWER_OBJS) $(CORE_TARGET) $(PREVIEWER_TARGET)

.PHONY: all clean third_party
